package com.shujia.control;

import com.shujia.pojo.Dept;
import com.shujia.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("mysql")
public class MySQLController {

    @Autowired
    DeptService deptService;

    @RequestMapping("dept")
    public String getDept(){
       return deptService.getDept();
    }

    @RequestMapping(value = "/all",method = RequestMethod.GET)
    public List<Dept> getAllCusBaseInfo(){
        return deptService.getAllCusBaseInfo();
    }

    /**
     * 保存客户信息
     *
     * 需要通过URL传入 dept 对象,而对象传入在JAVA中一般都是一JSON格式传输
     *    将对象信息转换成JSON
     * @param dept
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public Dept saveCusBaseInfo(@RequestBody Dept dept){
        return deptService.saveDeptInfo(dept);
    }

    /**
     * 根据客户ID查询客户信息
     * @param deptno
     * @return
     */
    // 通过 http://localhost:8081/cus/get/10 调用
    @RequestMapping(value = "/get/{deptno}",method = RequestMethod.GET)
    public Dept getCusBaseInfoById(@PathVariable("deptno") Integer deptno){
        System.out.println("该方法被调用...");
        return deptService.getDeptByNo(deptno);
    }
}
